﻿using System;
using System.Reflection;

namespace AttributeStudy
{
	public enum Animal
	{
		Dog = 1,
		Cat,
		Bird
	}

	public class AnimalType : Attribute
	{
		protected Animal thePet;
		public AnimalType(Animal pet)
		{
			thePet = pet;
		}

		public Animal Pet
		{
			get { return thePet; }
			set { thePet = Pet; }
		}
	}

	class AnimalTypeTestClass
	{
		[AnimalType(Animal.Dog)]
		public void DogMethod()
		{
		}

		[AnimalType(Animal.Cat)]
		public void CatMethod()
		{
		}

		[AnimalType(Animal.Bird)]
		public void BirdMethod()
		{
		}
	}


	class Program
	{
		static void Main(string[] args)
		{
			AnimalTypeTestClass testClass = new AnimalTypeTestClass();

			Type type = testClass.GetType();

			foreach (MethodInfo method in type.GetMethods())
			{
				foreach (Attribute attr in Attribute.GetCustomAttributes(method))
				{
					if (attr.GetType() == typeof(AnimalType))
					{
						Console.WriteLine("Hello {0} has a pet {1} attribute.",
											method.Name,
											((AnimalType)attr).Pet);
					}
				}
			}
		}
	}
}
